package com.my.study.exception;

import com.my.study.enums.BusinessExceptionEnum;
import lombok.Data;

@Data
public class BusinessException extends RuntimeException {

    private String code;
    private String msg;

    public BusinessException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public static BusinessException fail(String code, String msg) {
        BusinessException businessException = new BusinessException(code, msg);
        return businessException;
    }

    public static BusinessException fail(String msg) {
        BusinessException businessException = new BusinessException(BusinessExceptionEnum.FAIL.code, msg);
        return businessException;
    }

    public static BusinessException fail(Throwable throwable) {
        BusinessException businessException = new BusinessException(BusinessExceptionEnum.FAIL.code, throwable.getMessage());
        return businessException;
    }
}
